package com.etc.service.impl;

import java.util.Date;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.etc.dao.LogMapper;
import com.etc.dao.UserMapper;
import com.etc.entity.Log;
import com.etc.entity.User;
import com.etc.service.UserService;
import com.etc.util.PageData;
@Service("userService")
public class UserServiceImpl implements UserService {
	@Resource
	private UserMapper usermaper;
	@Resource
	private LogMapper logMapper;

	@Override
	public User getUserById(int userid) {
		return usermaper.selectByPrimaryKey(userid);
	}

	@Override
	//read=true设置只读，就不能进行增删改，只能查
	@Transactional(propagation=Propagation.REQUIRED,isolation=Isolation.READ_COMMITTED,readOnly=false)//代表这个方法是事务，也可以加在类的前面，表示所有的方法都是事务
	public boolean addUser(User user) {
		int n=usermaper.insert(user);
		return n>0;
	}
/**
 * 分页
 */
	@Override
	public PageData<User> getUsersByPage(int page, int pageSize, String content) {
		int start=(page-1)*pageSize;
		List<User> data=usermaper.getUserByPage(start, pageSize, content);
		int count=usermaper.getTotal(content);
		PageData<User> pd=new PageData<>(data, count, pageSize, page);
		return pd;
	}



@Override
public boolean delUsers(int userid) {
	// TODO Auto-generated method stub
	return usermaper.deleteByPrimaryKey(userid)>0;
}

@Override
public boolean update(User user) {
	// TODO Auto-generated method stub
	return usermaper.updateByPrimaryKey(user)>0;
}

}
